package com.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dao.ComboDao;
import com.enetiy.Area;
import com.enetiy.Areausable;
import com.enetiy.Comboinfo;
import com.enetiy.Comborecord;

public class ComboDaoImpl extends HibernateDaoSupport implements ComboDao {

	@Override
	public List<Comboinfo> selectUserComboList(int userid) throws Exception {
		Query query = this.getSession().createQuery("from Comboinfo where users_id = ?");
		query.setParameter(0, userid);
		List<Comboinfo> list = query.list();
		return list;
	}

	@Override
	public List<Comboinfo> selectUserComboList(int userid, int status)
			throws Exception {
		Query query = this.getSession().createQuery("from Comboinfo where users_id = ? and status =?");
		query.setParameter(0, userid);
		query.setParameter(1, status);
		List<Comboinfo> list = query.list();
		return list;
	}

	@Override
	public void insertUserCombo(Comboinfo comboinfo) throws Exception {
		this.getHibernateTemplate().save(comboinfo);
	}

	@Override
	public void deleteUserCombo(Comboinfo comboinfo) throws Exception {
		this.getHibernateTemplate().delete(comboinfo);
		
	}

	@Override
	public Comboinfo selectUserCombo(int id) throws Exception {
		return this.getHibernateTemplate().get(Comboinfo.class, id);
	}

	

	@Override
	public void insertUserComboRecord(Comborecord comborecord) throws Exception {
		this.getHibernateTemplate().save(comborecord);
	}

	@Override
	public void updateUserCombo(Comboinfo comboinfo) throws Exception {
		this.getHibernateTemplate().update(comboinfo);
		
	}

	@Override
	public Comboinfo selCombo(int userid, int comboid) throws Exception {
		Query query = this.getSession().createQuery("from Comboinfo where users_id = ? and comboid = ?");
		query.setParameter(0, userid);
		query.setParameter(1, comboid);
		List<Comboinfo> list = query.list();
		return list.isEmpty()?null:list.get(0);
	}

}
